﻿@model StudentCreateViewModel
@inject IStudentRepository _studentRepository


@{
    ViewBag.Title = "创建学生信息";
}

@*
    enctype=:表单提交给服务器,对提交的数据如何编码
    application/x-www-form-urlencoded:不指定,默认选项.发送前对所有字符进行编码
    text/plain:空格转换为加号,不对特殊字符进行编码
    multipart/form-data:不对字符进行编码
*@

<form enctype="multipart/form-data" asp-controller="home" asp-action="create" method="post" class="mt-3">

    <div asp-validation-summary="All" class="text-danger"></div>


    <div class="form-group row">
        <label asp-for="Name" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="Name" class="form-control" placeholder="请输入名字" />
            <span asp-validation-for="Name" class="text-danger"></span>
        </div>

    </div>

    <div class="form-group row">
        <label asp-for="Email" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="Email" class="form-control" placeholder="请输入邮箱" />
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
    </div>

    <div class="form-group row">
        <label asp-for="ClassName" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <select asp-for="ClassName" asp-items="Html.GetEnumSelectList<ClassNameEnum>()" class="custom-select mr-sm-2">
                <option value="">请选择</option>
            </select>
            <span asp-validation-for="ClassName" class="text-danger"></span>
        </div>
    </div>

    <div class="form-group row">
        <label asp-for="Photo" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <div class="custom-file">
                <input asp-for="Photo" multiple class="form-control custom-file-input" />
                <label class="custom-file-label">请选择照片....</label>
            </div>
        </div>
    </div>

    <div class="form-group row">
        <input type="submit" value="创建" class="btn btn-primary" />
    </div>

    <div class="form-group row">
        <div class="col-sm-10">
            学生信息总人数 @_studentRepository.GetAllStudents().Count()
        </div>
    </div>


    @section Scripts
    {
        <script>


            $(function () {

                //单文件上传
                $('.custom-file-input').on("change", function ()
                {
                    //console.log($(this).val());

                    //pop(),用于删除数组中其他元素,并返回数组中最后一个元素
                    var filename = $(this).val().split("\\").pop();

                    //console.log(filename);

                    $(this).next(".custom-file-label").html(filename);

                });


                //多文件上传
                //$('.custom-file-input').on("change", function () {

                //    console.log($(this));

                //    var fileLabel = $(this).next(".custom-file-label");

                //    var files = $(this)[0].files;

                //    if (files.length>1) {

                //        fileLabel.html("你已经选择了" + files.length+"个文件");

                //    } else {
                //        fileLabel.html(files[0].name);
                //    }

                //});

            });


        </script>
    }

</form>